var self = require('sdk/self');
var { Cc, Ci } = require('chrome');
var buttons = require("sdk/ui/button/action");
var preferencesService = require("sdk/preferences/service");

var common = require("common");
var {Converter} = require("data/PageScripts/Converter");
var server = require("server");
var {initHub, makeCallable} = server;
var tabs = require("tabs");
var logger = require("logger");

var converter = new Converter();
log = logger.log;
error = logger.error;

//-----------------------------------------------------------------------------------------------
// Workflow
//-----------------------------------------------------------------------------------------------
if(common.debug.disableClickPlay)
{
    preferencesService.set("plugins.click_to_play", false);
    preferencesService.set("plugin.default.state", 2);
}

var button = buttons.ActionButton({
    id: "my-button1",
    label: "my button1",
    icon: "./icon-16.png",
    onClick: server.test
});


// init logger
logger.init();

// init tabs manager's communication channel with server
tabs.init(converter, server, logger);

// initialize hub
server.init(converter, logger);

// do some test automatically
try
{
    server.test();
}
catch(e)
{
    error("Error in test : \n" +
        "Line Number : " + e.lineNumber + "\n" +
        "Error Message : " + e.message + "\n");
}